<template>
  <div>
    <div class="top">
      <div class="db">
        <i
          class="el-icon-collection-tag"
          style="color: rgb(255, 103, 0); font-size: 30px"
        ></i>
        <span style="font-size: 30px; font-weight: normal">我的收藏</span>
      </div>
    </div>
    <div class="w2 w">
      <ul>
        <li
          v-for="item in collect"
          :key="item.id"
          @click="$router.push(`/goods/details?productID=${item.product_id}`)"
        >
          <span class="ss" @click.stop="out(item.product_id)">X</span>
          <img
            :src="`http://101.132.181.9/api/${item.product_picture}`"
            alt=""
          />
          <h2>
            {{ item.product_name }}
          </h2>
          <h3>
            {{ item.product_title }}
          </h3>
          <p>
            <span>{{ item.product_selling_price }}元</span>
            <span class="del">{{ item.product_price }}元</span>
          </p>
        </li>
      </ul>
      <el-empty v-if="collect.length == 0" description="购物车为空"></el-empty>
    </div>
  </div>
</template>

<script>
import { getCollect, delCollect } from "@/api/user";
export default {
  data() {
    return {
      collect: [],
    };
  },
  mounted() {
    this.getCollectList();
  },
  methods: {
    //删除
    async out(id) {
      const res = await delCollect({
        user_id: this.$store.getters.userID,
        product_id: id,
      });
      this.getCollectList();
      this.$message.success("删除成功");
      console.log(res.data);
    },
    //渲染数据
    async getCollectList() {
      const res = await getCollect({ user_id: this.$store.getters.userID });
      console.log(res.data);
      this.collect = res.data.collectList;
    },
  },
};
</script>

<style scoped lang="scss">
.top {
  height: 70px;
  width: 100%;
  line-height: 70px;
  border-bottom: 2px solid rgb(255, 103, 0);
  background: #fff !important;
  i {
    margin-left: 180px;
  }
}

ul {
  // height: 500px;
  float: left;
  background-color: #f5f5f5;
  margin-top: 30px;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  justify-content: space-around;

  li {
    margin: 10px;
    background: #fff;
    width: 234px;
    height: 300px;
    margin-top: 10px;
    transition: all 0.2s linear;
    .ss {
      float: right;
      &:hover {
        cursor: pointer;
      }
    }
    img {
      width: 160px;
      height: 160px;
      margin: 0 0 0 25px;
    }
    a {
      display: block;
      text-align: center;
      line-height: 258px;
    }
    h2 {
      margin: 25px 10px 0;
      font-size: 14px;
      color: #333;
    }
    h3 {
      margin: 5px 10px;
      height: 18px;
      font-size: 12px;
      color: #b0b0b0;
    }
    p {
      margin: 10px 10px 10px;
      text-align: center;
      color: #ff6700;
    }
    .del {
      margin-left: 0.5em;
      color: #b0b0b0;
      text-decoration: line-through;
    }
    h2,
    h3 {
      font-weight: 400;
      text-align: center;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
  }
  li:hover {
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }
}
</style>
